package com.yq.bdm.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据，extends HashMap<String, Object>
 * 
 * @author shangpan
 * 
 * @date 2016年10月27日 下午9:59:27
 */
public class ResultMap extends HashMap<String, Object> {

	private static final long serialVersionUID = 4347183762087136007L;

	public static final String R_KEY_CODE = "code";
	public static final String R_KEY_MSG = "msg";
	public static final String R_KEY_DATA = "data";

	private static final int R_CODE_VALUE_SUCCESS = 0; // 操作无异常
	private static final int R_CODE_VALUE_ERROR = 9; // 操作异常

	public ResultMap() {
		put(R_KEY_CODE, R_CODE_VALUE_SUCCESS);
		put(R_KEY_MSG, "操作成功");
	}

	public static ResultMap error() {
		return error(R_CODE_VALUE_ERROR, "操作失败");
	}

	public static ResultMap error(String msg) {
		return error(R_CODE_VALUE_ERROR, msg);
	}

	public static ResultMap error(int code, String msg) {
		return new ResultMap().put(R_KEY_CODE, code).put(R_KEY_MSG, msg);
	}

	public static ResultMap ok(String msg) {
		return new ResultMap().put(R_KEY_MSG, msg);
	}

	public static ResultMap ok(Map<String, Object> map) {
		ResultMap r = new ResultMap();
		r.putAll(map);
		return r;
	}

	public static ResultMap ok() {
		return new ResultMap();
	}

	@Override
	public ResultMap put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
